//
//  main.m
//  C06_2_结构体
//
//  Created by dllo on 15/11/24.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Person.h"/* 导入头文件*/


int main(int argc, const char * argv[]) {

    /* 定义Pers结构体类型变量*/

    Person per1 = {"zhang", 20, 'm', 1};
    Person per2 = {"lisi", 19, 'f', 2};
    Person per3 = {"wang", 21, 'm', 3};
    hello();
    
//    informationOfPerson(per1);
//    informationOfPerson(per2);
    /*定义一个数组*/
    Person arrPerson[3] = {per1, per2, per3};
    /* 需求 将数组中元素按照年龄大小升序排序*/
    Person temp = {};
    for (int i = 0; i < 3 - 1; i++) {
        for (int j = 0; j < 3 - 1 - i; j++) {
            if (arrPerson[j].age > arrPerson[j + 1].age) {
                
                temp = arrPerson[j];
                arrPerson[j] = arrPerson[j + 1];
                arrPerson[j + 1] = temp;
            }
        }
    }
//    for (int i = 0; i < 3; i++) {
//        informationOfPerson(arrPerson[i]);
//    }
    
    /* 需求 将数组中元素按照姓名升序排序*/
    int a;
    for (int i = 0; i < 3 - 1; i++) {
        for (int j = 0; j < 3 - 1 - i; j++) {
          a =  strcmp(arrPerson[j].name, arrPerson[j + 1].name);
            if (a > 0) {
                temp = arrPerson[j];
                arrPerson[j] = arrPerson[j + 1];
                arrPerson[j + 1] = temp;
            }
        }
    }
        for (int i = 0; i < 3; i++) {
            informationOfPerson(arrPerson[i]);
        }

    
    
    
    
    
    return 0;
}
